from pydantic_settings import BaseSettings
from typing import Optional
import os
from functools import lru_cache
from dotenv import load_dotenv

# 加载.env文件
load_dotenv()


class Settings(BaseSettings):
    # 应用配置
    APP_NAME: str = "AI Chat System API"
    VERSION: str = "1.0.0"
    DEBUG: bool = True
    
    # 数据库配置
    DATABASE_URL: str = "sqlite:///./chat_ai_system.db"
    
    # 安全配置
    SECRET_KEY: str = os.getenv("SECRET_KEY", "your-secret-key-here-change-in-production")
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
    
    # CORS配置
    BACKEND_CORS_ORIGINS: list = ["*"]
    
    # AI配置
    AI_API_KEY: Optional[str] = os.getenv("AI_API_KEY")
    
    class Config:
        env_file=".env"
        env_file_encoding="utf-8"
        case_sensitive=False


# 创建全局设置实例
settings = Settings()